package com.ibm.risk.irmp.workflow.client.flowable.api;

import com.ibm.risk.irmp.workflow.client.flowable.ApiClient;

import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseHistoricCaseInstanceResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.HistoricCaseInstanceQueryRequest;
import com.ibm.risk.irmp.workflow.client.flowable.model.HistoricCaseInstanceResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.HistoricIdentityLinkResponse;
import java.time.OffsetDateTime;
import com.ibm.risk.irmp.workflow.client.flowable.model.StageResponse;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;


@Component("com.ibm.risk.irmp.flowable.api.HistoryCaseApi")
public class HistoryCaseApi {
    private ApiClient apiClient;

    public HistoryCaseApi() {
        this(new ApiClient());
    }

    @Autowired
    public HistoryCaseApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     *  Delete a historic case instance
     *
     * <p><b>204</b> - Indicates that the historic process instance was deleted.
     * <p><b>404</b> - Indicates that the historic process instance could not be found.
     * @param caseInstanceId The caseInstanceId parameter
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public void deleteHistoricCaseInstance(String caseInstanceId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'caseInstanceId' is set
        if (caseInstanceId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'caseInstanceId' when calling deleteHistoricCaseInstance");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("caseInstanceId", caseInstanceId);
        String path = UriComponentsBuilder.fromPath("/cmmn-history/historic-case-instances/{caseInstanceId}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = { };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
        apiClient.invokeAPI(path, HttpMethod.DELETE, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get a historic case instance
     *
     * <p><b>200</b> - Indicates that the historic process instances could be found.
     * <p><b>404</b> - Indicates that the historic process instances could not be found.
     * @param caseInstanceId The caseInstanceId parameter
     * @return HistoricCaseInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public HistoricCaseInstanceResponse getHistoricCaseInstance(String caseInstanceId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'caseInstanceId' is set
        if (caseInstanceId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'caseInstanceId' when calling getHistoricCaseInstance");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("caseInstanceId", caseInstanceId);
        String path = UriComponentsBuilder.fromPath("/cmmn-history/historic-case-instances/{caseInstanceId}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<HistoricCaseInstanceResponse> returnType = new ParameterizedTypeReference<HistoricCaseInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     *
     *
     * <p><b>200</b> - successful operation
     * @param caseInstanceId The caseInstanceId parameter
     * @return List&lt;StageResponse&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public List<StageResponse> getStageOverview(String caseInstanceId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'caseInstanceId' is set
        if (caseInstanceId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'caseInstanceId' when calling getStageOverview");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("caseInstanceId", caseInstanceId);
        String path = UriComponentsBuilder.fromPath("/cmmn-history/historic-case-instances/{caseInstanceId}/stage-overview").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<List<StageResponse>> returnType = new ParameterizedTypeReference<List<StageResponse>>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * List identity links of a historic case instance
     *
     * <p><b>200</b> - Indicates request was successful and the identity links are returned
     * <p><b>404</b> - Indicates the process instance could not be found..
     * @param caseInstanceId The caseInstanceId parameter
     * @return List&lt;HistoricIdentityLinkResponse&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public List<HistoricIdentityLinkResponse> listHistoricCaseInstanceIdentityLinks(String caseInstanceId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'caseInstanceId' is set
        if (caseInstanceId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'caseInstanceId' when calling listHistoricCaseInstanceIdentityLinks");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("caseInstanceId", caseInstanceId);
        String path = UriComponentsBuilder.fromPath("/cmmn-history/historic-case-instances/{caseInstanceId}/identitylinks").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<List<HistoricIdentityLinkResponse>> returnType = new ParameterizedTypeReference<List<HistoricIdentityLinkResponse>>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * List of historic case instances
     *
     * <p><b>200</b> - Indicates that historic case instances could be queried.
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information.
     * @param caseInstanceId An id of the historic case instance.
     * @param caseDefinitionKey The process definition key of the historic case instance.
     * @param caseDefinitionId The process definition id of the historic case instance.
     * @param businessKey The business key of the historic case instance.
     * @param involvedUser An involved user of the historic case instance.
     * @param finished Indication if the historic case instance is finished.
     * @param finishedAfter Return only historic case instances that were finished after this date.
     * @param finishedBefore Return only historic case instances that were finished before this date.
     * @param startedAfter Return only historic case instances that were started after this date.
     * @param startedBefore Return only historic case instances that were started before this date.
     * @param startedBy Return only historic case instances that were started by this user.
     * @param includeCaseVariables An indication if the historic case instance variables should be returned as well.
     * @param tenantId Only return instances with the given tenantId.
     * @param withoutTenantId If true, only returns instances without a tenantId set. If false, the withoutTenantId parameter is ignored.
     * @return DataResponseHistoricCaseInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricCaseInstanceResponse listHistoricCaseInstances(String caseInstanceId, String caseDefinitionKey, String caseDefinitionId, String businessKey, String involvedUser, Boolean finished, OffsetDateTime finishedAfter, OffsetDateTime finishedBefore, OffsetDateTime startedAfter, OffsetDateTime startedBefore, String startedBy, Boolean includeCaseVariables, String tenantId, Boolean withoutTenantId) throws RestClientException {
        Object postBody = null;

        String path = UriComponentsBuilder.fromPath("/cmmn-history/historic-case-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "caseInstanceId", caseInstanceId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "caseDefinitionKey", caseDefinitionKey));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "caseDefinitionId", caseDefinitionId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "businessKey", businessKey));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "involvedUser", involvedUser));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "finished", finished));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "finishedAfter", finishedAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "finishedBefore", finishedBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "startedAfter", startedAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "startedBefore", startedBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "startedBy", startedBy));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "includeCaseVariables", includeCaseVariables));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "tenantId", tenantId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "withoutTenantId", withoutTenantId));

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricCaseInstanceResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricCaseInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Query for historic case instances
     * All supported JSON parameter fields allowed are exactly the same as the parameters found for getting a collection of historic case instances, but passed in as JSON-body arguments rather than URL-parameters to allow for more advanced querying and preventing errors with request-uri’s that are too long. On top of that, the query allows for filtering based on process variables. The variables property is a JSON-array containing objects with the format as described here.
     * <p><b>200</b> - Indicates request was successful and the case instances are returned
     * <p><b>400</b> - Indicates an parameter was passed in the wrong format. The status-message contains additional information.
     * @param body The body parameter
     * @return DataResponseHistoricCaseInstanceResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseHistoricCaseInstanceResponse queryHistoricCaseInstance(HistoricCaseInstanceQueryRequest body) throws RestClientException {
        Object postBody = body;

        String path = UriComponentsBuilder.fromPath("/cmmn-query/historic-case-instances").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseHistoricCaseInstanceResponse> returnType = new ParameterizedTypeReference<DataResponseHistoricCaseInstanceResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
}
